<template>
  <div>
    <dl class="m-proifo clearfix">
      <dt class="f-pr">
        <img :src="detail.Url" alt="" />
      </dt>
      <dd>
        <div class="name clearfix">
          <h2 class="f-f1">
            <span class="tit f-f1">{{ detail.nickname }}</span>
            <span class="f-f1 vip-4 vip-level"></span>
            <span class="lev f-f1"
              >{{ detail.level }}
              <i class="levr"></i>
            </span>
            <i class="u-icn"></i>
          </h2>
          <div class="f-f1">
            <a href="#" class="btn u-btn1">
              <i>发私信</i>
            </a>
            <!-- <a href="#" class="btn u-btn3">
                              <i>已关注</i>
                          </a> -->
            <a href="#" class="btn u-btn2"> 关 注 </a>
          </div>
        </div>
        <ul class="data clearfix">
          <li class="fst">
            <a href="javascript:;">
              <strong>{{detail.eventCount}}</strong>
              <span>动态</span>
            </a>
          </li>
          <li>
            <a href="javascript:;">
              <strong>{{detail.follows}}</strong>
              <span>关注</span>
            </a>
          </li>
          <li>
            <a href="javascript:;">
              <strong>{{detail.followeds}}</strong>
              <span>粉丝</span>
            </a>
          </li>
        </ul>
        <div class="inf" v-if="detail.signature.length">
          <span>个人介绍：{{detail.signature}}</span>
        </div>
        <!-- <div class="inf">
          <span>所在地区：四川省 - 成都市</span>
        </div> -->
      </dd>
    </dl>
    <DetailPlay v-if="p_s_flag" :nid='personal_id'/>

    <div class="u-title-1">
      <h3>
        <span class="f-ff"
          >{{ detail.nickname }}创建的歌单
          <span class="f-pa"></span>
          <span class="f-1">({{detail.playlistCount}})</span>
        </span>
      </h3>
    </div>
    <ul class="m-cvrlst clearfix">
      <li v-for="el in create_date" :key="el.id">
        <div class="u-cover">
          <img :src="el.coverImgUrl + '?param=140y140'" />
          <!-- <a href="javascript:;" > </a> -->
          <router-link :to="{
              path:'/playlist',
              query:{
                  id:el.id
              }
          }" :title="el.name" class="msk"></router-link>
          <div class="btm">
            <a href="javascript:;" class="icon-play" @mousedown="ss(el.id)"> </a>
            <span class="icon-headset"></span>
            <span class="nb">{{ el.playCount }}</span>
          </div>
          <p class="dec">
        
            <router-link :to="{
              path:'/playlist',
              query:{
                  id:el.id
              }
          }" :title="el.name"  class="f-th overtext"> {{ el.name }}</router-link>
          </p>
        </div>
      </li>
    </ul>

    <div class="u-title-1" v-if="col_date.length">
      <h3>
        <span class="f-ff"
          >{{ detail.nickname }}收藏的歌单
          <span class="f-pa"></span>
          <!-- <span class="f-1">({{col_date.length}})</span> -->
        </span>
      </h3>
    </div>
    <ul class="m-cvrlst clearfix" ref="mc">
      <li v-for="el in col_date" :key="el.id">
        <div class="u-cover">
          <img :src="el.coverImgUrl + '?param=140y140'" />
          <a href="javascript:;" :title="el.name" class="msk"> </a>
          <div class="btm">
            <a href="javascript:;" class="icon-play"> </a>
            <span class="icon-headset"></span>
            <span class="nb">{{ el.playCount }}</span>
          </div>
          <p class="dec">
            <a href="javascript:;" :title="el.name" class="f-th overtext">
              {{ el.name }}
            </a>
          </p>
        </div>
      </li>
      <span class="load" v-if="!more_flag">
        <img src="../images/5-121204193Q9-50.gif" alt="" />
      </span>
    </ul>
  </div>
</template>

<script>
import axios from "axios";

import DetailPlay from "../components/DetailPlay.vue";
export default {
  name: "PersonalPage",
  data() {
    return {
      personal_id: "1418490674",
      Data_20: [],
      playData: [],

      detail: {
        nickname: "",
        Url: "",
        level: "",
        followeds:'',
        follows:'',
        eventCount:'',
        playlistCount:'',
        signature:'' 
      },
      p_s_flag: false,
      create_date: [],
      col_date: [],
      dis: "",
      more_flag: true,
      
    };
  },
  components: {
    DetailPlay,
  },
  methods: {
      ss(value){
          axios.get('http://localhost:8080/api/playlist/detail',{
            params:{
                id:value,

            },
            headers:{
                withCredentials: true,
            }
        }).then ( (response) =>{
           
             this.$bus.$emit('musicLists',response.data.playlist.tracks);
        })
      }
  },
  mounted() {
    this.personal_id = this.$route.query.id;
  
    this.$bus.$emit('p_num_id',this.personal_id);
    axios
      .get("http://localhost:8080/api/user/detail", {
        params: {
          uid: this.personal_id,
        },
        headers: {
          withCredentials: true,
        },
      })
      .then((response) => {
         
        this.p_s_flag = response.data.peopleCanSeeMyPlayRecord;

        this.detail.Url = response.data.profile.avatarUrl;
        this.detail.nickname = response.data.profile.nickname;
        this.detail.level = response.data.level;
        this.detail.followeds = response.data.profile.followeds;
        this.detail.follows = response.data.profile.follows;
        this.detail.eventCount = response.data.profile.eventCount;
        this.detail.playlistCount = response.data.profile.playlistCount;
        this.detail.signature = response.data.profile.signature;
      });
    axios
      .get("http://localhost:8080/api/user/playlist", {
        params: {
          uid: this.personal_id,
        },
        headers: {
          withCredentials: true,
        },
      })
      .then((response) => {
        if (response.data.playlist.length <= 30) {
            this.$bus.$emit("m_flag", false);
        }
        
        response.data.playlist.forEach((element) => {
          if (element.userId == this.personal_id) {
            this.create_date.push(element);
          } else {
            this.col_date.push(element);
          }
        });
      });
   

    this.$bus.$on("scr", () => {
    
      if (window.pageYOffset >  document.documentElement.offsetHeight - document.documentElement.clientHeight - 245) {
        if (this.more_flag) {
             this.more_flag = false
          axios
            .get("http://localhost:8080/api/user/playlist", {
              params: {
                uid: this.personal_id,
                limit: "30",
                offset: this.create_date.length + this.col_date.length,
              },
              headers: {
                withCredentials: true,
              },
            })
            .then((response) => {
                
                this.more_flag = true;
                if (response.data.playlist.length == 0) {
                    this.$bus.$emit("m_flag", false);
               
                }
               
               
              
              response.data.playlist.forEach((element) => {
                if (element.userId == this.personal_id) {
                  this.create_date.push(element);
                } else {
                  this.col_date.push(element);
                }
              });
            });
        }
      }
    });
  },
};
</script>

<style lang="less" scoped>


.m-proifo {
  margin-bottom: 43px;
  .name {
    padding-bottom: 12px;
    margin-bottom: 10px;
    border-bottom: 1px solid #ddd;
    .tit {
      float: left;
      margin-top: 3px;
      font-size: 22px;
      font-weight: normal;
      line-height: 30px;
      color: #000;
    }
  }
  dd {
    float: left;
  }
}
.f-pr {
  float: left;
  width: 188px;
  margin-right: 40px;
  img {
    display: inline-block;
    width: 180px;
    height: 180px;
    padding: 3px;
    background: #fff;
    border: 1px solid #d5d5d5;
  }
}
.f-f1 {
  float: left;
}

.vip-level {
  width: 57px;
  height: 36px;
  background-size: 100% 20px;
  background-repeat: no-repeat;
  background-position: center;
  float: left;
  margin-left: 10px;
}

.lev {
  margin: 8px 0 0 10px;
  display: inline-block;
  height: 19px;
  overflow: hidden;
  padding-left: 29px;
  line-height: 21px;
  color: #e03a24;
  font-size: 14px;
  font-weight: bold;
  font-style: italic;
  background: url(../images/icon2.png) no-repeat -135px -190px;
  i {
    float: right;
    width: 9px;
    height: 19px;
    background: url(../images/icon2.png) no-repeat -191px -190px;
    vertical-align: middle;
    overflow: hidden;
  }
}
.u-icn {
  float: left;
  margin: 9px 0 0 8px;
  width: 20px;
  height: 20px;
  background: url(../images/icon.png) no-repeat -41px -27px;
}
.btn {
  float: left;
  margin: 4px 0 0 15px;
}
.u-btn1 {
  width: 75px;
  height: 31px;
  background: url(../images/button.png) no-repeat 0 -810px;
  i {
    display: inline-block;
    height: 29px;
    line-height: 29px;
    padding-left: 25px;
  }
  &:hover {
    background: url(../images/button.png) no-repeat 0 -845px;
  }
}
.u-btn2 {
  width: 40px;
  height: 31px;
  padding: 0 4px 0 26px;
  line-height: 30px;
  background: url(../images/button.png) no-repeat 0 -720px;
  color: #fff;
}
.u-btn3 {
  width: 70px;
  height: 31px;
  line-height: 30px;
  background: url(../images/button.png) no-repeat 0 -919px;
  padding-left: 8px;
}
.data {
  height: 41px;
  margin-bottom: 15px;
  color: #666;
  li {
    float: left;
    padding: 0 40px 0 20px;
    border-left: 1px solid #ddd;
    a {
      &:hover {
        text-decoration: none;
        color: #0c73c2;
      }
    }
    strong {
      line-height: 28px;
      display: block;
      margin-top: -4px;
      font-size: 24px;
      font-weight: normal;
      cursor: pointer;
      text-align: left;
    }
  }
  .fst {
    padding-left: 0;
    border-left: none;
  }
}
.inf {
  margin-bottom: 5px;
  line-height: 21px;
  color: #666;
  text-align: left;
}
.u-title-1 {
  height: 33px;
  border-bottom: 2px solid #c20c0c;
  color: #666;
  text-align: left;
  h3 {
    float: left;
    font-size: 20px;
    line-height: 28px;
    font-weight: normal;
  }
  h4 {
    float: left;

    margin: 4px 0 0 10px;
    line-height: 26px;
    font-weight: 400;
  }
}

.f-ff {
  position: relative;
  color: #333;
}
.f-pa {
  position: absolute;
  display: inline-block;
  width: 8px;
  height: 8px;
  top: 1px;
  background: url(../images/black-r-icon@3x.png) no-repeat;
  background-size: cover;
}
.f-1 {
  margin: 0 0 0 12px;
}
.m-cvrlst {
  margin: 20px 0 0 -50px;
  li {
    height: 165px;
    overflow: hidden;
    float: left;
    width: 140px;
    padding: 0 0 30px 50px;
    line-height: 1.4;
  }
}
.u-cover {
  position: relative;
  width: 140px;
  height: 140px;
  img {
    display: block;
    width: 100%;
    height: 100%;
  }
  .msk {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url(../images/coverall.png) no-repeat 0 0;
  }
  .icon-play {
    position: absolute;
    right: 10px;
    bottom: 5px;
    width: 16px;
    height: 17px;
    background: url(../images/iconall.png) no-repeat 0 0;
  }
  .icon-headset {
    float: left;
    width: 14px;
    height: 11px;
    margin: 9px 5px 9px 10px;
    background: url(../images/iconall.png) no-repeat 0 -24px;
  }
  .nb {
    float: left;
    margin: 7px 0 0 0;
  }
}
.btm {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 27px;
  color: #ccc;
  background: url(../images/coverall.png) no-repeat 0 -537px;
}
.f-th {
  display: inline-block;
  max-width: 100%;
  vertical-align: middle;
  color: #333;
}
.dec {
  margin: 8px 0 3px;
  font-size: 14px;
  width: 100%;
}
.load {
    display: inline-block;
  width: 100%;
  text-align: center;
  img {
      height: 20px;
  }
}
dd {
    width: 670px;
}
</style>